<%@ page import="java.io.* , java.util.*, java.sql.*,  com.jipl.dao.*,com.jipl.beans.*"%>
<html xmlns="http://www.w3.org/1999/xhtml">
    <!-- DW6 -->
    <head>
        <!-- Copyright 2005 Macromedia, Inc. All rights reserved. -->
        <title>Item Master</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <script src="../../SpryAssets/SpryValidationSelect.js" type="text/javascript"></script>
        <script language="javascript" type="text/javascript" src="../../Scripts/ItemMasterValidations.js"></script>
        <script type="text/javascript">

            function getXMLObject()  //XML OBJECT
            {
                var xmlHttp = false;
                try {
                    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")  // For Old Microsoft Browsers
                }
                catch (e) {
                    try {
                        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")  // For Microsoft IE 6.0+
                    }
                    catch (e2) {
                        xmlHttp = false   // No Browser accepts the XMLHTTP Object then false
                    }
                }
                if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
                    xmlHttp = new XMLHttpRequest();        //For Mozilla, Opera Browsers
                }
                return xmlHttp;  // Mandatory Statement returning the ajax object created
            }

            var xmlhttp = new getXMLObject();	//xmlhttp holds the ajax object

            function getGroups() {
                var sel = document.getElementById("item_type");
                var opt = sel.options[sel.selectedIndex];
                var d = opt.value || opt.text;

                if(xmlhttp) {
                    xmlhttp.open("GET","../../AJAXItemGroup?itype=" +d,true);
                    xmlhttp.onreadystatechange  = handleServerResponse;
                    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                    xmlhttp.send(null);
                }
            }
			
            function handleServerResponse() {
                if (xmlhttp.readyState == 4) {
                    if(xmlhttp.status == 200) {
                        document.getElementById('item_group').options.length = 0;
                        var elemnt = document.getElementById("item_group");
                        var textToSplit = xmlhttp.responseText;
                        var returnElements=textToSplit.split("|");
                        var valueLabelPair=null;
                        for ( var i=0; i<(returnElements.length-1); i++ ){
                            document.getElementById('item_group').options[i] = new Option("","");
                        }
                        document.getElementById('item_group').options[0] = new Option("Select","");
                        for ( var i=0; i<(returnElements.length-1); i++ ){
                            valueLabelPair = returnElements[i].split("|");
                            document.getElementById('item_group').options[i+1] = new Option(valueLabelPair[0], valueLabelPair[1]);
                        }
                    }else {
                        alert("Error during AJAX call. Please try again");
                    }
                }
            }
        </script>
        <style type="text/css">
            <!--
            .style1 {
                color: #F4FFE4;
                font-weight: bold;
            }
            -->
        </style>
        <link href="../../images/mm_health_nutr.css" rel="stylesheet" type="text/css">
        <style type="text/css">
            <!--
            a {
                font-size: 12px;
                font-weight: bold;
            }
            a:link {
                text-decoration: none;
            }
            a:visited {
                text-decoration: none;
            }
            a:hover {
                text-decoration: none;
            }
            a:active {
                text-decoration: none;
            }
            .style13 {
                color: #506C3B;
                font-weight: bold;
                font-size: 12px;
            }
            -->
        </style>
        <link href="../../SpryAssets/SpryValidationSelect.css" rel="stylesheet" type="text/css">
        <style type="text/css">
            <!--
            .style17 {
                color: #FFFFFF;
                font-weight: bold;
            }
            .style18 {color: #FFFFFF}
            .style20 {font-weight: bold}
            -->
        </style>
    </head>
    <body bgcolor="#F4FFE4">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td height="550" align="center" valign="top" bgcolor="#5C743D">&nbsp;
                    <p>&nbsp;</p>

                    <form id="form" name="ShowItem" method="post" action="../../ShowItems">
                        <table width="769" border="0" align="center" cellpadding="0" cellspacing="0" style="border-right: #FFFFFF 1px solid;
                               border-top: #FFFFFF 1px solid; border-left: #FFFFFF 1px solid;  border-bottom: #FFFFFF 1px solid; font-size: 9pt; color: #000000; font-family: Arial;">
                            <tr>
                                <td height="30" colspan="5" align="center" valign="middle" background="../../images/flash_header1.png" bgcolor="#506C3B"><span class="style13">Adding Items</span></td>
                            </tr>
                            <tr>
                                <td width="181" height="26" align="center" valign="middle"><span class="style1">item Type </span></td>
                                <td width="186" height="26" align="left" valign="middle">
                                    <select name='item_type' id="item_type"  onChange="javascript:getGroups();">
                                        <option selected="selected"></option>
                                        <%
        ItemMasterDao imdao = new ItemMasterDao();
        Vector gp = imdao.getTypes();
        if (gp != null) {
            System.out.println("IN..................." + gp.size());
            Iterator itg = gp.iterator();
            while (itg.hasNext()) {
                ItemTypeBean gb = (ItemTypeBean) itg.next();
                String pname = gb.getType_name();
                                        %>
                                        <option value="<%=pname%>"><%=pname%></option>
                                        <%}

        }%>
                                    </select>            </td>
                                <td width="139" align="center" valign="middle" background="../../images/flash_body1.png">
                                <td width="76" align="left" valign="middle" background="../../images/flash_body1.png"><span class="style17">ItemGroup</span></td>
                                <td width="187" align="left" valign="middle" background="../../images/flash_body1.png">

                                    <select name="item_group" id="item_group" onChange="javascript:getItems()">
                                        <option>Select</option>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td height="26" colspan="5" align="center" valign="middle"><label>
                                        <input type="submit" name="button" id="button" value="Add Item">
                                    </label></td>
                            </tr>
                        </table>
                    </form>
                    <script language="javascript">
                        document.getElementById("optionCount").value=0;
                    </script></td>
            </tr>
        </table>

    </body>
</html>
